<template>
    <div class="bc-header">
        <div class="bc-header-inner">
            <div class="left-content">培训管理系统</div>
            <div class="right-content">
                <div class="right-content-span" @click="goSelfUrl('strain.index')" v-if="showStrain">
                    <i class="iconfont icon-a-tuichu1x tohome"></i> 
                    培训管理系统
                </div> 
                <el-dropdown popper-class="drop-menu-wrap">
                    <div class="nav-item pointer">
                        <img class="user-img" :src="currentUser.icon || config.defaultImg" alt="">
                        <span class="user-name">{{ username }}</span>
                    </div>
                    <template #dropdown>
                        <ul class="user-avatar-select-wrap">
                            <!-- <li class="user-option-item" v-if="showPersonCenter" @click="goSelfUrl('home.userHomePage')">个人中心</li> -->
                            <!-- <li class="user-option-item" v-if="showManage" @click="goSelfUrl('idxmc.index')">管理中心</li> -->
                            <!-- <li class="user-option-item" v-if="showStrain" @click="goSelfUrl('strain.index')">培训管理系统</li> -->
                            <li class="user-option-item" @click="exit">退出</li>
                        </ul>
                    </template>
                </el-dropdown> 
                <!-- <template v-else>
                    <span class="login-btn pointer" @click="goLogin">{{isRegist ? '登录/注册': '登录'}}</span>
                </template> -->
            </div>    
        </div>
    </div>
</template>

<script setup>
import { pageJump } from '@/global/location-transfer';
import { getUrl } from '@/router/jumpHref';
import { reactive, computed, watch } from 'vue';
import config from '@/global/config'
import { useStore } from 'vuex';

const store = useStore();

const sourceMap = reactive({
    strain: {
        title: '培训管理系统'
    }
});

const currentUser = computed(() => {
    return store.state.currentUser || {};
})
const username = computed(() => {
    return currentUser.value?.realName || currentUser.value?.name || ''
})

const showManage = computed(() => { // 是否显示管理中心
    let pagePermission = store.state?.pagePermission || {};
    let isHaveIdmx = store.state.user?.isHaveIdmx;
    return !!pagePermission['manageCenter:base:home'] && isHaveIdmx;
})

const showPersonCenter = computed(() => { // 是否显示个人中心
    let pagePermission = store.state?.pagePermission || {};
    return !!pagePermission['personalCenter:page']
})

const showStrain = computed(() => { // 是否显示培训管理系统
    let pagePermission = store.state?.pagePermission || {};
    let isHaveStrain = store.state.user?.isHaveStrain;
    return !!pagePermission.continuingEducation && !!pagePermission.train && isHaveStrain;
})

function goSelfUrl (str) {
    let url = getUrl(str);
    pageJump(url, '_blank');
}

function goLogin () {
    store.dispatch('logout');
}

function exit() {
   store.dispatch('logoutHome');
}
</script>

<style lang="scss" scoped>
 // 主页导航主色
$nav-main-color: #000000;
  // 主页导航选中主色
$nav-main-active-color: #000000;
 // 主页更多下拉导航背景主色
$nav-main-sub-bg-more-color: rgba(255, 255, 255, 0.92);
// 主页更多下拉导航文字主色
$nav-main-sub-color: #222222;
 // 主页更多下拉导航文字hover主色
$nav-main-sub-hover-color: #279731;

 // 首页主色
$home-main-color: var(--srt-main-active-text-color);
.bc-header {
    width: 100%;
    min-width: 1200px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px !important;
    background: $home-main-color;
    box-shadow: 0px 1px 6px 0px rgba(0, 0, 0, 0.06);
}
.bc-header-inner {
    width: 1200px;
    line-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.left-content,
.right-content {
    display: flex;
    align-items: center;
}
.left-content{
    color: #ffffff;
    font-size: 16px;
    font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
    font-weight: bold;
    color: #FFFFFF;
    line-height: 21px;
}
.tohome {
    opacity: 0.95;
    font-size: 20px;
    font-style: normal;
    vertical-align: middle;
}
.right-content-span {
    color: #fff;
    cursor: pointer;
    padding-right: 17px;
    font-size: 14px;
    font-weight: 400;
    opacity: 0.95;
}
.news-img-wrap {
    position: relative;
    .has-message {
        width: 8px;
        height: 8px;
        background: #FF4719;
        border: 1px solid #FFFFFF;
        border-radius: 50%;
        position: absolute;
        top: 1px;
        right: 1px;
    }
}
.news-img {
    width: 22px;
    height: 22px;
}
.user-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}
.nav-item {
    display: flex;
    align-items: center;
    margin-left: 20px;
    color: #fff;
    cursor: pointer;
    .user-img {
        margin-right: 8px;
    }
    // &::after {
    //     content: '';
    //     color: #fff;
    //     background: url(~static/img/login/head-down.png) no-repeat;
    //     width: 10px;
    //     height: 10px;
    //     background-size: contain;
    //     margin-left: 6px;
    //     display: inline-block;
    // }
}
.middle-divider{
    position: relative;
    margin: 1px 20px;
    &::before {
        position: absolute;
        content: '';
        top:-5px;
        left: 0;
        height: 12px;
        width: 1px;
        background-color: #ccc;
    }
}
.mar-l40 {
    padding: 10px 15px 20px 15px;
}
.title-hover {
    &:hover {
        color: $nav-main-sub-hover-color
    }
}
.login-btn {
    width: 94px;
    height: 32px;
    background: $home-main-color;
    border-radius: 4px;
    display: inline-block;
    color: #ffffff;
    line-height: 32px;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
}
.user-avatar-select-wrap {
    // padding: 16px 22px;
    // min-width: 100px;
    padding: 5px 0;
    font-size: 14px;
    font-family: MicrosoftYaHei;
    .user-option-item {
        // margin-bottom: 20px;
        // margin: 0 0 20px;
        padding: 7px 16px;
        cursor: pointer;
        // width: 56px;
        color: #515a6e;
        text-align: center;
        &:hover {
            background: #efefef;
        }
    }
}
</style>

<style lang="scss">
.drop-menu-wrap {
    min-width: 100px;
    top: 65px!important;
    box-shadow: 0px 1px 6px rgba(0,0,0,0.2) !important;
    .el-popper__arrow::before {
        display: none;
    }
}
</style>